package cn.ex;

public class Ex6 {
    public static void main(String[] args) {
        //检查一个字符串在另一个字符串出现的次数
        String a = "java";
        String b = "javahello,java 1.8,okjava18";

        //System.out.println(b.contains(a));//true
        //System.out.println(b.indexOf(a));//6
        //System.out.println(b.lastIndexOf(a));//16

        int num = 0;
        int start = 0;
        while((start = b.indexOf(a,start))!=-1){
            start++;
            ++num;
        }
        //System.out.println(num);
        System.out.printf("字符串：%s，在字符串：%s，共出现：%d次%n",a,b,num);
    }
}
